<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace App\Info\Mapper;

use App\Info\Model\InfoRecruitment;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 招骋要求Mapper类
 */
class InfoRecruitmentMapper extends AbstractMapper
{
    /**
     * @var InfoRecruitment
     */
    public $model;

    public function assignModel()
    {
        $this->model = InfoRecruitment::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        
        // ID
        if (isset($params['id']) && filled($params['id'])) {
            $query->where('id', '=', $params['id']);
        }

        // 分类名称
        if (isset($params['name']) && filled($params['name'])) {
            $query->where('name', 'like', '%'.$params['name'].'%');
        }

        // 要求
        if (isset($params['ask_require']) && filled($params['ask_require'])) {
            $query->where('ask_require', 'like', '%'.$params['ask_require'].'%');
        }

        // 薪资待遇
        if (isset($params['salary_benefits']) && filled($params['salary_benefits'])) {
            $query->where('salary_benefits', 'like', '%'.$params['salary_benefits'].'%');
        }

        // 创建者
        if (isset($params['addr']) && filled($params['addr'])) {
            $query->where('addr', 'like', '%'.$params['addr'].'%');
        }

        // 备注
        if (isset($params['remark']) && filled($params['remark'])) {
            $query->where('remark', 'like', '%'.$params['remark'].'%');
        }

        // 状态
        if (isset($params['status']) && filled($params['status'])) {
            $query->where('status', '=', $params['status']);
        }

        // 创建时间
        if (isset($params['create_time']) && filled($params['create_time'])) {
            $query->where('create_time', '=', $params['create_time']);
        }

        // 更新时间
        if (isset($params['update_time']) && filled($params['update_time'])) {
            $query->where('update_time', '=', $params['update_time']);
        }

        return $query;
    }
}